package com.fyt.ZhongYaoApp.Controller;

import com.fyt.ZhongYaoApp.pojo.Browsingrecord;
import com.fyt.ZhongYaoApp.pojo.Essay;
import com.fyt.ZhongYaoApp.pojo.PageBean;
import com.fyt.ZhongYaoApp.pojo.Result;
import com.fyt.ZhongYaoApp.pojo.pg.EssayPG;
import com.fyt.ZhongYaoApp.pojo.vo.BrowsingrecordVO;
import com.fyt.ZhongYaoApp.service.EssayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/essay")
public class EssayController {

    @Autowired
    private EssayService essayService;

    /**
     * 查看文章列表
     * @return
     */
    @GetMapping("/list")
    public Result<List<Essay>> list() {
        List<Essay> list = essayService.EssayList();
        return Result.success(list);
    }

    /**
     * 根据id查找文章
     * @return
     */
    @PostMapping("/find")
    public Result<Essay> findEssayById(@RequestBody Essay essay) {
        Essay essay1 = essayService.findEssayById(essay.getId());
        return Result.success(essay1);
    }

    /**
     * 添加浏览记录
     * @param browsingrecord
     * @return
     */
    @PostMapping("/addTime")
    public Result<Browsingrecord> addBrowsingrecord(@RequestBody Browsingrecord browsingrecord) {


        return Result.success(essayService.addBrowsingrecord(browsingrecord));
    }

    /**
     * 根据用户id查找浏览记录
     * @param essayPG
     * @return
     */
    @PostMapping("findAccessTimeByUserId")
    public Result<PageBean<Essay>> findAccessTimeByUserId(@RequestBody EssayPG essayPG) {

        return Result.success(essayService.findAccessTimeByUserId(essayPG));
    }

}
